home *** CD-ROM | disk | FTP | other *** search
/ PC World Interactive 1 / PC World Interactive 1 - Nisan 1997.iso / nostalji / bbs / music / sbbook.arj / SBBOOK / SOURCE / TC / PLAYVOCX.C < prev   
Encoding:
C/C++ Source or Header  |  1993-10-27  |  3.7 KB  |  137 lines

  1. /*********************************************************************
  2. *
  3. *  PROGRAM NAME: PLAYVOCX.C
  4. *
  5. *  COMPILER:     Borland/Turbo C/C++
  6. *
  7. *  DESCRIPTION: Plays a .VOC file from extended memory using the
  8. *               CT-VOICE.DRV driver (accessed from SBSIM).  To run
  9. *               the program, type the following at the command line:
  10. *
  11. *               PLAYVOCX FILENAME
  12. *
  13. *               Where FILENAME is the drive/path/filename of the .VOC
  14. *               file to play.
  15. *
  16. *  NOTE: SBSIM driver must be loaded before running this program.
  17. *
  18. *********************************************************************/
  19. #define VOC_MEM_DRIVER  0x04
  20.  
  21. #include <ctype.h>
  22. #include <conio.h>
  23. #include <fcntl.h>
  24. #include <io.h>
  25. #include <stdio.h>
  26. #include "drvrfunc.c"
  27. #include "drvrfunc.h"
  28.  
  29.  
  30. /********************************************************************/
  31. void main(int argc, char **argv)
  32. {
  33.   char   Command,
  34.      UserQuit;
  35.  
  36.   int    FileHandle,
  37.      SBSIMHandle;
  38.  
  39.   SIMERR RetValue;
  40.  
  41.   if (argc != 2)  // argc = no. of parameters entered on command line
  42.   {
  43.     puts("Command line must contain EXACTLY ONE filename parameter!");
  44.     return;  // Terminate program
  45.   }
  46.  
  47.  
  48.   /*--- SEE IF SBSIM DRIVER HAS LOADED ------------*/
  49.   SIMint = FindDvr("SBSIM", 0x0103);  // Get SBSIM's interrupt no.
  50.   if (SIMint == 0)
  51.   {
  52.     puts("SBSIM driver not loaded!");
  53.     return;  // Terminate program
  54.   }
  55.  
  56.   /*--- SEE IF CT-VOICE.DRV DRIVER HAS LOADED -------*/
  57.   if (!(GetDrvrs() & VOC_MEM_DRIVER))
  58.   {
  59.     puts("CT-VOICE.DRV not loaded!");
  60.     return;  // Terminate program
  61.   }
  62.  
  63.  
  64.   /*--- OPEN THE FILE SPECIFIED ON COMMAND LINE (stored in argv[1]) ----*/
  65.   if ((FileHandle = _open(argv[1], O_BINARY | O_RDONLY)) == -1)
  66.   {
  67.     printf("FILE: %s not successfully opened!\n", argv[1]);
  68.     return;  // Terminate program
  69.   }
  70.  
  71.   /*--- LOAD THE FILE INTO EXTENDED MEMORY ----------*/
  72.   SBSIMHandle = LoadExtMem((void far *) argv[1]);
  73.   _close(FileHandle);  // Done with the file, close it!
  74.  
  75.  
  76.   /*--- StartSnd() INITIALIZES CT-VOICE DRIVER ------*/
  77.   RetValue = StartSnd(MemVoice, (void far *) 0, EXTENDED_MEM_VOC,
  78.               SBSIMHandle);
  79.   if (RetValue != SIMerr_NoErr)
  80.   {
  81.     printf("ERROR CALLING SBSIM: %s\n", errorMsg[RetValue]);
  82.     return;  // Terminate program
  83.   }
  84.  
  85.   /*--- PlaySnd() BEGINS PLAYING THE FILE ------------*/
  86.   RetValue = PlaySnd(MemVoice);
  87.   if (RetValue != SIMerr_NoErr)
  88.   {
  89.     printf("ERROR CALLING SBSIM: %s\n", errorMsg[RetValue]);
  90.     if(FreeExtMem(SBSIMHandle) != 0)
  91.     {
  92.       puts("ERROR: Error freeing extended memory");
  93.       return;
  94.     }
  95.     return;  // Terminate program
  96.   }
  97.  
  98.   clrscr();  // Clear screen
  99.   printf("\n\n\n\n\n     SELECT ONE OF THE FOLLOWING OR WAIT UNTIL DONE:\n\n");
  100.   printf("                   (P)ause\n");
  101.   printf("                   (R)esume\n");
  102.   printf("                   (Q)uit\n");
  103.  
  104.   UserQuit = FALSE;
  105.  
  106.   /*--- PROCESS USER INTERACTION OR WAIT FOR SOUND TO STOP -----------*/
  107.   do
  108.   {
  109.     if (kbhit())  // Was a key pressed?
  110.     {
  111.       Command = toupper(getch()); // Get char typed and convert to upper case
  112.       if (Command == 'P')
  113.     PauseSnd(MemVoice);
  114.       else if (Command == 'R')
  115.     ResumeSnd(MemVoice);
  116.       else if (Command == 'Q')
  117.     UserQuit = TRUE;
  118.     }
  119.     // Exit do-while loop if file is done playing or user typed 'Q'
  120.   } while (GetSndStat(MemVoice) != 0 && UserQuit == FALSE);
  121.  
  122.  
  123.   /*--- IF SOUND IS STILL PLAYING AND USER HIT 'Q', STOP THE SOUND ---*/
  124.   if (GetSndStat(MemVoice) != 0 && UserQuit == TRUE)
  125.     StopSnd(MemVoice);
  126.  
  127.  
  128.   /*--- FREE UP EXTENDED MEMORY THAT FILE WAS LOADED INTO ------------*/
  129.   if(FreeExtMem(SBSIMHandle) != 0)
  130.   {
  131.     puts("ERROR: Error freeing extended memory");
  132.     return;
  133.   }
  134.  
  135.   return;
  136. }
  137.